<template>
  <div>
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <a-form @submit="submit" :form="form">
        <a-form-item
        label="字典类型"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-input
          v-decorator="[
            'dictType',
            { rules: [{ required: true, message: '字典类型不得为空' }] },
          ]"
          placeholder="字典类型"
        />
      </a-form-item>
      <a-form-item
        label="字典类型名"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-input
          v-decorator="[
            'dictTypeName',
            { rules: [{ required: true, message: '字典类型不得为空' }] },
          ]"
          placeholder="字典类型名"
        />
      </a-form-item>
      <a-form-item
        label="字典键值"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-input
          v-decorator="[
            'dictValue',
            { rules: [{ required: true, message: '字典类型不得为空' }] },
          ]"
          placeholder="字典类型名"
        />
      </a-form-item>
      <a-form-item
        label="字典标签"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-input
          v-decorator="[
            'dictLabel',
            { rules: [{ required: true, message: '字典类型不得为空' }] },
          ]"
          placeholder="字典类型名"
        />
      </a-form-item>
      <a-form-item
        label="字典排序"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-input-number
          v-decorator="['dictSort', { rules: [{ required: true }] }]"
        />
      </a-form-item>
      <a-form-item
        label="是否启用"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-switch
          checkedChildren="开"
          unCheckedChildren="关"
          v-decorator="[
            'enabled',
            {
              valuePropName: 'checked',
              rules: [{ required: true, message: '请填写是否开启' }],
            },
          ]"
        />
      </a-form-item>
      <a-form-item
        style="margin-top: 24px"
        :wrapperCol="{ span: 10, offset: 7 }"
      >
        <a-button type="primary" @click="submit">{{ $t("submit") }}</a-button>
      </a-form-item>
      </a-form>
    </a-card>
    <footer-tool-bar>
      <a-button type="primary" @click="submit" :loading="loading">{{
        $t("submit")
      }}</a-button>
    </footer-tool-bar>
  </div>
</template>

<script>
import { saveOrUpdateDict } from "@/services/dict";
import FooterToolBar from "@/components/tool/FooterToolBar";

export default {
  name: "BasicForm",
  i18n: require("./i18n"),
  components: { FooterToolBar },
  data() {
    return {
      form: this.$form.createForm(this),
      value: 1,
    };
  },
  mounted() {},
  methods: {
    submit() {
      this.form.validateFields((err, values) => {
        if (!err) {
          saveOrUpdateDict(values).then((rep) => {
            if (rep.data.success) {
              this.$message.success("新增字典数据成功");
            } else {
              this.$message.error(rep.data.msg);
            }
          });
        }
      });
    },
  },
  computed: {
    desc() {
      return "同字典类型内字典键值不可重复";
    },
  },
};
</script>

<style scoped>
</style>
